package com.carl.leetcode.bit;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by carlXie on 2016/1/14.
 * email: kkrimen@gmail.com
 */
public class SubSet {
    public static void main(String[] args) {
        int[] nums = {1, 2, 3};
        List<List<Integer>> list = subsets(nums);
    }

    public static List<List<Integer>> subsets(int[] nums) {
        int len = nums.length;

        Arrays.sort(nums);
        List<List<Integer>> list = new ArrayList<List<Integer>>();

        for (long i = 0, listSize = 1 << len; i < listSize; i++) {
            List<Integer> subList = new ArrayList<Integer>();
            for (int j = 0; j < len; j++) {
                if((i & i << j) > 0) {
                    subList.add(nums[j]);
                    System.out.printf(nums[j] + " ");
                }
            }
            System.out.println();
            list.add(subList);
        }

        return list;
    }

}
